home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / powertb.arc / TREEDIRS.INC < prev    next >
Encoding:
Text File  |  1985-02-24  |  5.0 KB  |  210 lines

  1. { Turbo Pascal routines for tree-structured directories
  2.   Copywrite 1984 Michael A. Covington }
  3.  
  4. { Requires MS-DOS or PC-DOS 2.0 or higher, except as noted. }
  5.  
  6. { All routines require these type definitions.
  7.   However, except as noted, they do not require each other. }
  8.  
  9. type pathtype  = string[63];
  10.      drivetype = string[2];
  11.      rtype     = record
  12.                     ax,bx,cx,dx,bp,si,di,ds,es,flags : integer
  13.                     end;
  14.  
  15. {===============================}
  16. procedure xxdiskerr(x:drivetype);
  17. {===============================}
  18. begin
  19.    writeln('Error -- Invalid disk drive, ''',x,'''');
  20.    halt
  21. end;
  22.  
  23. {==============================}
  24. procedure xxpatherr(x:pathtype);
  25. {==============================}
  26. begin
  27.    writeln('Error -- Invalid path, ''',x,'''');
  28.    halt
  29. end;
  30.  
  31. {===============================}
  32. function currentdrive: drivetype;
  33. {===============================}
  34.  
  35. { Return designator for current default drive, e.g. 'A:'. }
  36. { Works under DOS version 1. }
  37.  
  38. var w  : drivetype;
  39.    reg : rtype;
  40. begin
  41.    reg.ax := $1900;
  42.    intr($21,reg);
  43.    w := 'A:';
  44.    w[1] := chr(ord(w[1])+lo(reg.ax));
  45.    currentdrive := w
  46. end;
  47.  
  48. {=============================}
  49. procedure chdrive(x:drivetype);
  50. {=============================}
  51.  
  52. { Choose a new default drive.
  53.   Parameter can have the form of 'A:', 'a:', 'A', or 'a'.
  54.   Works under DOS Version 1.  Requires XXDISKERR above.   }
  55.  
  56. var reg : rtype;
  57.  
  58. begin
  59.    reg.ax := $0E00;
  60.    reg.dx := ord(upcase(x[1])) - ord('A');
  61.    intr($21,reg);
  62.    if (reg.dx < 0) or (lo(reg.ax) < lo(reg.dx)) then xxdiskerr(x);
  63. end;
  64.  
  65. {====================================}
  66. function diskspace(x:drivetype): real;
  67. {====================================}
  68.  
  69. { Return number of bytes available on specified disk.
  70.   Parameter can have the form of 'A:', 'a:', 'A', or 'a'.
  71.   Requires XXDISKERR above.   }
  72.  
  73. var reg : rtype;
  74.  
  75. begin
  76.    reg.ax := $3600;
  77.    reg.dx := 1 + ord(upcase(x[1])) - ord('A');
  78.    intr($21,reg);
  79.    if (reg.ax = $ffff) then
  80.       xxdiskerr(x)
  81.    else
  82.       diskspace := (256.0*hi(reg.dx)+lo(reg.dx))*reg.ax*reg.cx
  83. end;
  84.  
  85. {=========================================}
  86. function currentdir(x:drivetype): pathtype;
  87. {=========================================}
  88.  
  89. { Returns full path to active directory on specified drive,
  90.   including backslash ath the beginning, not including
  91.   drive designator.  Parameter as for CHDRIVE.
  92.   Requires XXDISKERR above.   }
  93.  
  94. var w   : pathtype;
  95.     reg : rtype;
  96.     i   : integer;
  97.  
  98. begin
  99.    { get current path }
  100.    reg.ax := $4700;
  101.    reg.dx := 1 + ord(upcase(x[1])) - ord ('A');
  102.    reg.ds := seg(w[1]);
  103.    reg.si := ofs(w[1]);
  104.    intr($21,reg);
  105.    if (reg.flags and 1) > 0 then xxdiskerr(x);
  106.  
  107.    { turn it into a Turbo string }
  108.    i := 1;
  109.    while w[i]<>chr(0) do begin
  110.       w[i] := upcase(w[i]);
  111.       i := i +1
  112.       end;
  113.    w[0] := chr(i-1);
  114.  
  115.    currentdir := '\' + w
  116. end;
  117.  
  118. {=====================================}
  119. procedure xxdir(x:pathtype; k:integer);
  120. {=====================================}
  121.  
  122. { Executes CHDIR, MKDIR, and RMDIR requests.
  123.   Requires XXPAATHERR and CURRENTDRIVE, above. }
  124.  
  125. var w   : pathtype;
  126.     reg : rtype;
  127.  
  128. begin
  129.    w := x + chr(0);
  130.    if w[2] <> ':' then { add drive designator }
  131.       w := currentdrive + w;
  132.    reg.ax := k;
  133.    reg.ds := seg(w[1]);
  134.    reg.dx := ofs(w[1]);
  135.    intr($21,reg);
  136.    if (reg.flags and 1) > 0 then xxpatherr(x)
  137. end;
  138.  
  139. {==========================}
  140. procedure chdir(x:pathtype);
  141. {==========================}
  142.  
  143. { Equivalent to CHDIR command in DOS.
  144.   Requires XXDIR, XXPATHERR, and CURRENTDRIVE, above.
  145.   Caution!  Do not leave a directory
  146.   if you have files in it open.
  147. }
  148. begin
  149.    xxdir(x,$3800)
  150. end;
  151.  
  152. {==========================}
  153. procedure rmdir(x:pathtype);
  154. {==========================}
  155.  
  156. { Equivalent to RMDIR command in DOS.
  157.   Requires XXDIR, XXPATHERR, and CURRENTDRIVE, above.
  158. }
  159. begin
  160.    xxdir(x,$3A00)
  161. end;
  162.  
  163. {==========================}
  164. procedure mkdir(x:pathtype);
  165. {==========================}
  166.  
  167. { Equivalent to MKDIR command in DOS.
  168.   Requires XXDIR, XXPATHERR, and CURRENTDRIVE, above.
  169. }
  170. begin
  171.    xxdir(x,$3900)
  172. end;
  173.  
  174. {=============================}
  175. procedure rename(x,y:pathtype);
  176. {=============================}
  177.  
  178. { Rename a file; unlike the DOS RENAME command,
  179.   both parameters of this command are full paths.
  180.   The paths need not be the same, allowing a file
  181.   to be moved from one directory to another.
  182.   First parameter can specify a drive; any drive
  183.   letter on the second parameter is ignored.
  184. }
  185. var wx, wy : pathtype;
  186.     reg    : rtype;
  187.  
  188. begin
  189.    wx := x + chr(0);
  190.    wy := y + chr(0);
  191.    if wx[2]<>':' then wx := currentdrive + wx;
  192.    reg.ax := $5600;
  193.    reg.ds := seg(wx[1]);
  194.    reg.dx := ofs(wx[1]);
  195.    reg.es := seg(wy[1]);
  196.    reg.di := ofs(wy[1]);
  197.    intr($21,reg);
  198.    if (reg.flags and 1) <> 0 then begin
  199.       writeln('Error -- invalid rename request');
  200.       writeln('      -- From: ''',x,'''');
  201.       writeln('      -- To:   ''',y,'''');
  202.       halt
  203.       end
  204. end;
  205.  
  206.  
  207.  
  208.  
  209.  
  210.